" 1.定义字典
" 用 \ 表示换行
let animal_names = {
    \ 'cat' : 'Miss Cattington',
    \ 'dog' : 'Mr Dogson',
    \ 'parrot' : 'Polly'
\ }

echo animal_names

" 2.1.获取字典中的元素
let cat_name = animal_names['cat']
" 2.2.另一种获取字典中元素的方法
echo cat_name
let cat_name = animal_names.cat
echo cat_name

" 3.设置或修改元素
let animal_names['raven']='Raven R. Raventon'
echo animal_names

" 4.1.使用unlet删除元素
unlet animal_names['raven']
echo animal_names
" 4.2.使用remove删除元素
let parrot = remove(animal_names, 'parrot')
echo parrot

" 5.两个字典合并
" 如果第二个字典有相同的键，会覆盖
call extend(animal_names, {'bobcat':'Sir Meowtington'})
echo animal_names

" 6.检查空
" 7.长度计算
if ! empty(animal_names)
    echo 'We have names is ' . len(animal_names) . ' animals'
endif

" 8.检查某个键是否存在
if has_key(animal_names, 'cat')
    echo 'Cat''s name is ' . animal_names['cat']
endif

" :help dict